<?php

namespace App\Jobs;

use App\Model\User;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;

class ClearWeight implements ShouldQueue
{
    use InteractsWithQueue, Queueable, SerializesModels;

    protected $openId;

    /**
     * ClearWeight constructor.
     *
     * @param $openId
     */
    public function __construct($openId)
    {
        $this->openId = $openId;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $user = User::firstOrCreate(['open_id' => $this->openId]);

        $user->weight = 0;

        $user->save();
    }
}
